<?php
header("Content-type:text/html; charset=utf-8");

class Mysql{
	public $mysql,$result,$row,$result_array_one,$result_array_all;
	function __construct(){
		$this->mysql=new PDO("mysql:host=localhost;dbname=ruiyou_info","root","root");
		if(!$this->mysql) exit(0);
		$this->mysql->query("set names utf8");
		
		$this->result_array_all=array();
		$this->result_array_one=array();
	}
	function __destruct(){
		$this->mysql=NULL;
	}
}

class interview extends Mysql{
	function __construct(){
		parent::__construct();
	}
	function getAllitem(){
		$this->result_array_all=array();
		
		$this->result=$this->mysql->prepare("select * from interview_item");
		$this->result->execute();
		
		while($this->row=$this->result->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['id']=$this->row['id'];
			$this->result_array_one['date']=$this->row['date'];
			$this->result_array_one['name']=$this->row['name'];
			$this->result_array_one['job']=$this->row['job'];
			$this->result_array_one['interviewer']=$this->row['interviewer'];
			$this->result_array_one['resume']=$this->row['resume'];
			$this->result_array_one['result']=$this->row['result'];
			$this->result_array_one['other']=$this->row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
	}
	
	function getAllitem1(){
		$this->result_array_all=array();
		
		$this->result=$this->mysql->prepare("select * from interview_item where status=0 order by id desc");
		$this->result->execute();
		
		while($this->row=$this->result->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['id']=$this->row['id'];
			$this->result_array_one['date']=$this->row['date'];
			$this->result_array_one['name']=$this->row['name'];
			$this->result_array_one['job']=$this->row['job'];
			$this->result_array_one['interviewer']=$this->row['interviewer'];
			$this->result_array_one['resume']=$this->row['resume'];
			$this->result_array_one['result']=$this->row['result'];
			$this->result_array_one['other']=$this->row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
	}
	
	function getAllitem2(){
		$this->result_array_all=array();
		
		$this->result=$this->mysql->prepare("select * from interview_item where status=1 order by id desc");
		$this->result->execute();
		
		while($this->row=$this->result->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['id']=$this->row['id'];
			$this->result_array_one['date']=$this->row['date'];
			$this->result_array_one['name']=$this->row['name'];
			$this->result_array_one['job']=$this->row['job'];
			$this->result_array_one['interviewer']=$this->row['interviewer'];
			$this->result_array_one['resume']=$this->row['resume'];
			$this->result_array_one['result']=$this->row['result'];
			$this->result_array_one['other']=$this->row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
	}
	
	function addItem($date,$name,$job,$interviewer,$resume,$result,$other){
		$insert=$this->mysql->prepare("insert into interview_item(date,name,job,interviewer,resume,result,other,status) values ('$date','$name','$job','$interviewer','$resume','$result','$other',0)");
		$status=$insert->execute();
		
		if($status){
			return 1;
		}else {
			return 0;
		}
	}
	function alterResult($id,$result){
		$alter=$this->mysql->prepare("update interview_item set result='$result',status=1 where id=$id");
		$status=$alter->execute();
		
		if($status){
			return 1;
		}else {
			return 0;
		}
	}
	
	function getSelectItem($keywork){
		$this->result_array_all=array();
		
		$this->result=$this->mysql->prepare("select * from interview_item where name like '%$keywork%' or interviewer like '%$keywork%' or job like '%$keywork%' or date like '%$keywork%' or result like '%$keywork%'");
		$this->result->execute();
		
		while($this->row=$this->result->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['id']=$this->row['id'];
			$this->result_array_one['date']=$this->row['date'];
			$this->result_array_one['name']=$this->row['name'];
			$this->result_array_one['job']=$this->row['job'];
			$this->result_array_one['interviewer']=$this->row['interviewer'];
			$this->result_array_one['resume']=$this->row['resume'];
			$this->result_array_one['result']=$this->row['result'];
			$this->result_array_one['other']=$this->row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
	}
	
	function __destruct(){
		parent::__destruct();
	}
}

function alert($string){
	echo "<script language='javascript'>";
	echo "alert('$string');";
	echo "</script>";
}

function open($string,$string2){
	echo "<script language='javascript'>";
	echo "window.open('$string','$string2');";
	echo "</script>";
}
?>
